package com.rop.znyx.product.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rop.znyx.model.product.Category;
import com.rop.znyx.product.mapper.CategoryMapper;
import com.rop.znyx.product.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rop.znyx.vo.product.CategoryQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品三级分类 服务实现类
 * </p>
 *
 * @author rop
 * @since 2023-06-24
 */

@Slf4j
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    /**
     * 获取商品分类列表
     */
    @Override
    public IPage<Category> selectByPage(Page<Category> pageParam, CategoryQueryVo categoryQueryVo) {
        String name = categoryQueryVo.getName();

        LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            queryWrapper.like(Category::getName, name);
        }

        return baseMapper.selectPage(pageParam, queryWrapper);
    }

    /**
     * 获取全部商品分类
     */
    @Override
    public List<Category> findAllList() {
        return baseMapper.selectList(null);
    }
}
